<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright    Copyright (c) 2006, Julien PORTALIER
 * @link         http://code.google.com/p/feather-cm
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

class Group extends ActiveRecord
{
	public $belongsTo        = array('Member');
	public $recursiveProcess = Q_PROCESS_LIST;
	public $recursiveFields  = 'name';
	
	function register($member_id, $groups)
	{
		$values = array();
		if (!is_array($groups))
			$groups = explode(',', str_replace(' ', '', $groups));
		foreach($groups as $grp)
			array_push($values, array($member_id, $grp));
		$this->saveMany('member_id, name', &$values);
	}
	
	function remove($member_id, $name)
	{
		// gets id
		$this->Group->conditions(array(
			'member_id' => $member_id,
			'name'      => $name
		));
		$id = $this->Group->field('id');
		
		// removes member from group
		return $id ? $this->Group->delete($id) : false;
	}
}
?>